<?php
/**
 * 冒泡排序
 * O(n2)
 * @param array   $seq A list of integers
 * @return array Return sorted array
 */

function bubble_sort(array $seq)
{
    $len = count($seq);
    for ($i = 0; $i < $len; $i++) {
        for ($j = 1; $j < $len; $j++) {
            if ($seq[$j] < $seq[$j - 1]) {
                $tem = $seq[$j];
                $seq[$j] = $seq[$j - 1];
                $seq[$j - 1] = $tem;
            }
        }
    }
    return $seq;
}


